home *** CD-ROM | disk | FTP | other *** search
- program fefix;
- {
- An effort to repair the headers in Borland
- Stroked Font files (filename.CHR) that are
- damaged as a result of a SAVE action by the
- Borland Font Editor FE.EXE, found in the
- BGI Toolkit BGIKIT.ZIP.
-
- Author: Jay Faubion
- Compuserve 72500,3166
- January 25, 1990
- Compiled with Turbo Pascal 5.5
- Released to the public domain
-
- Syntax: FEFIX [fontfilename] [FE-]
-
- The fontfilename is the name of the damaged font file.
- The FE- means do NOT execute FE.EXE
-
- FEFIX by itself will execute .\FE.EXE so that you may
- edit a font file, which should be then SAVED. The
- resulting file has a damaged header (signature).
- Next, FEFIX will prompt you for the file name of the
- damaged fontfile, and repair it for you.
-
- Revised 2/7/90: Although the Borland Font Editor was
- happy with the fixed font files, some Borland programs
- were not, generating an error -13 or -19. The code
- was changed to write a header identical to an existing
- fontfile header; the one for the V1.1 SANS.CHR file.
- The only changes made to that header are in the filename,
- which will be limited to four characters, and of course
- in the file-specific info such as filesize, etc.
-
- Specifics of the header info are found in the code to
- follow.
- }
- {$V-}
- {$M $4000,0,0 }
- {$L+}
-
- uses
- DOS,
- CRT;
-
- const
- Version = 'Version 1.01';
-
- type
- fontfile = file of byte;
-
- var
- inputfile, outputfile,backupfile : fontfile;
- i,j,k,x,y,filelen, gotparms : longint;
- b1,b2,b3,b4 : Byte;
- Infile,Outfile,backfile,
- Astr,BStr,CStr : string;
- TmpFlg, success : boolean;
- PStr : pathstr;
- DStr : dirstr;
- NStr : namestr;
- EStr : extstr;
- Directory : searchrec;
-
- function UCASE(VAR L2U:string) : String;
- VAR i : INTEGER;
- x : String;
- begin
- x := l2u;
- for i := 1 to length(x) DO x[i]:=upcase(x[i]);
- ucase := x;
- end;
-
- procedure Clear24;
- begin
- gotoxy(1,24);clreol;gotoxy(1,24);
- end;
-
- {----- Fix new filename -----}
- procedure FixFilenames;
- begin
- PStr := infile;
- Pstr := FExpand(Pstr);
- FSplit(Pstr,Dstr,Nstr,Estr);
- NStr := NStr+' ';
- b1:=$20;
- for i := 1 to 4 do
- begin
- if Nstr[i] = '.' then TmpFlg := true;
- b2:=ord(nstr[i]);
- if not TmpFlg then write(outputfile,b2)
- else write(outputfile,b1);
- end;
- end;
- {---- Fix file size ----}
- procedure FixFileSize;
- begin
- k := filelen div 256;
- j := filelen - (k*256);
- b1 := j;
- b2 := k;
- write(outputfile,b1); {low order}
- write(outputfile,b2); {high order}
- close(outputfile);
- end;
-
- { ---- Adjust header information --- }
- procedure AdjustHeader;
- begin
- Reset(Outputfile);
- TmpFlg := false;
- for i := $0 to $5B do read(outputfile,b1); { skip to filename }
- FixFilenames;
- for i := 1 to 4 do read(outputfile,b1); { skip to filesize }
- FixFileSize;
- end;
- procedure FontEditor;
- begin
- {$I-}
- assign(inputfile,'FE.EXE');
- reset(inputfile);
- {$I+}
- i := IOResult;
- if i <> 0 then
- begin
- writeln('FE.EXE not in current directory!');
- halt(1);
- end;
- SwapVectors;
- exec('FE.exe','');
- SwapVectors;
- end;
-
- function CheckFontName : boolean;
- begin
- {$I-}
- assign(InputFile,Infile);
- reset (InputFile);
- i := IOResult;
- if i=0 then CheckFontName:=true else CheckFontName:=false;
- if i=0 then close (InputFile);
- {$I+}
- end;
-
-
- Procedure GetFontName;
- begin
- success := false;
- While not success do
- begin
- clrscr;
- findfirst('*.CHR',$3F,Directory);
- if doserror<>18 then writeln( Directory.Name);
-
- while doserror <> 18 do
- begin
- findnext(Directory);
- if doserror<>18 then Writeln( Directory.name);
- end;
- Clear24;
- writeln('Fontnames should be four characters, plus the .chr extension.');
- write('Enter the name of the fontfile (filename.CHR): ');
- readln(InFile);
- if InFile <'@' then InFile := '@';
- success := CheckFontName;
- if Not Success then
- begin
- if Infile ='@' then InFile:='NONAME!';
- Clear24;
- writeln('Couldn''t open ',Infile,'.');
- halt(1);
- end;
- if Infile = Outfile then
- begin
- Clear24;
- writeln('The Input and Output files must have different names!');
- halt(1);
- end;
- end;
- end;
-
- { ---- Is this a damaged file? ---- }
- procedure CheckforDamage;
- begin
- for i := $0 to $80 do read(InputFile,b1);
- if b1 = $2B then begin
- Clear24;
- writeln('This file appears OK!');
- halt(1);end;
- close(inputfile); reset(inputfile);
- { ---- Is this a damaged file? ---- }
- end;
-
- procedure RenewHeader;
- var index,i,j,k : integer;
- t : array[0..8] of string;
- h : array[0..150] of integer;
-
- begin
- (* 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f *)
- (* -------------------------------------------------- *)
- t[1]:=' 80 75 8 8 66 71 73 32 83116114111107101100 32 ';
- t[2]:=' 70111110116 32 86 49 46 49 32 45 32 74117108 32 ';
- t[3]:=' 49 50 44 32 49 57 56 56 13 10 67111112121114105 ';
- t[4]:='103104116 32 40 99 41 32 49 57 56 55 44 49 57 56 ';
- t[5]:=' 56 32 66111114108 97110100 32 73110116101114110 ';
- t[6]:=' 97116105111110 97108 13 10 26128 0 83 65 78 83 ';
- t[7]:='198 52 1 0 1 0 0 0 0 0 0 0 0 0 0 0 ';
- t[8]:=' 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ';
- (* [1] P K B G I S t r o k e d
- [2] F o n t V 1 . 1 - J u l
- [3] 1 2 , 1 9 8 8 ^M ^J C o p y r i
- [4] g h t ( c ) 1 9 8 7 , 1 9 8
- [5] 8 B o r l a n d I n t e r n
- [6] a t i o n a l ^M ^J ^Z
- *)
-
- index :=0;
- for j := 1 to 8 do
- for i := 0 to 15 do
- begin
- val( copy(T[j],(i*3)+1,3) ,h[index],k);
- inc(index);
- end;
-
- inc(index); h[index] := 0;
- inc(index); h[index] := 0;
-
- filelen:=0;
- for i := $0 to $7F do
- begin
- b1:=h[i];
- write(Outputfile,b1);
- inc(filelen);
- end;
-
- for i := 1 to (128+92) do
- read(Inputfile,b1);
-
- while not eof(Inputfile) do
- begin
- read(Inputfile,b1);
- write(Outputfile,b1);
- inc(filelen);
- j:= filelen mod 100;
- end;
- close(Outputfile);
- Close(Inputfile);
- end;
-
- procedure CleanUp;
- begin
- Assign (Backupfile, Backfile) ; { Create and }
- Rewrite (BackUpFile) ; { Destroy a }
- Close (BackUpFile) ; { Backup }
- Erase (Backupfile) ; { File....... }
- Rename (InputFile, Backfile) ; { Input to Backup }
- Rename (OutPutFile, Infile) ; { Output to Original }
- end;
-
- procedure OpenFiles;
- begin
- assign (Outputfile, Outfile );
- Assign (Inputfile, Infile );
- rewrite (Outputfile );
- reset (Inputfile );
- end;
-
- begin
- clrscr;
- InFile := 'FEFIX.$' ;
- Outfile := 'FEFIX.$$' ;
- Backfile := 'FEFIX.$$$';
- TmpFlg := false;
- gotparms := paramcount;
- if gotparms >0 then
- AStr :=paramstr(1);
- AStr:=ucase(AStr);
- if AStr='FE-' then TmpFlg :=true
- else TmpFlg:=false;
- InFile:=Astr; { Get fontfile on command line}
- if gotparms >1 then
- begin
- AStr:=paramstr(2);
- AStr:=ucase(AStr);
- if AStr='FE-' then TmpFlg :=true
- else TmpFlg:=false;
- end;
- (**)
- if not TmpFlg then FontEditor; { Execute FE.EXE if present. }
- TmpFlg := CheckFontName; { Do we have a valid filename?}
- (**)
- if not TmpFlg then GetFontName; { No, ask user for a filename.}
-
- gotoxy(1,23);clreol;
- write('FEFIX ',version);
- OpenFiles; { Open the files to work on }
- clear24;
- write('Working on ',InFile,'...');
-
- CheckForDamage; { Is this a damaged file? }
- RenewHeader; { Write modified dummy header }
- AdjustHeader; { Patch header with good info }
- Cleanup; { Get all filenames right }
-
- Clear24;
- writeln ('Fontfile ',Infile,' repaired.');
- end.